package com.example.administrator.nl.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.nl.R;
import com.example.administrator.nl.base.BaseActivity;
import com.example.administrator.nl.util.CountTimerUtils;
import com.example.administrator.nl.util.ToastUtil;

import butterknife.BindView;

public class UpdatePassWordActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.iv_finish)
    ImageView iv_finish;

    @BindView(R.id.tv_title)
    TextView tv_title;

    @BindView(R.id.tv_submit_update)
    TextView tv_submit_update;

    @BindView(R.id.tv_verification_update)
    TextView tv_verification_update;

    @BindView(R.id.et_phone_update)
    EditText et_phone_update;

    @BindView(R.id.et_verification_update)
    EditText et_verification_update;

    @BindView(R.id.et_password_update)
    EditText et_password_update;

    @BindView(R.id.et_password_s_update)
    EditText et_password_s_update;

    CountTimerUtils mCountTimerUtils;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void init() {
        tv_title.setText("修改密码");
    }

    @Override
    public int getContentView() {
        return R.layout.activity_update_pass_word;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_finish:
                finish();
                break;
            case R.id.tv_verification_update:
                mCountTimerUtils = new CountTimerUtils(60000, 1000, tv_verification_update);
                mCountTimerUtils.start();
                break;
            case R.id.tv_submit_update:
                updatePassword();
                break;

            default:
                break;
        }
    }

    private void updatePassword() {
        if (!TextUtils.isEmpty(et_phone_update.getText())) {
            if (!TextUtils.isEmpty(et_verification_update.getText())) {

                if (!TextUtils.isEmpty(et_password_update.getText()) && !TextUtils.isEmpty(et_password_s_update.getText())) {

                    if (et_password_update.getText().toString().equals(et_password_s_update.getText().toString())) {
                        if (null != mCountTimerUtils) {
                            mCountTimerUtils.cancel();
                        }
                        ToastUtil.ToastShort("修改成功");
                        finish();


                    } else {
                        ToastUtil.ToastShort("两次密码不一致");

                    }
                } else {
                    ToastUtil.ToastShort("密码不能为空");

                }
            } else {
                ToastUtil.ToastShort("请输入验证码");

            }
        } else {
            ToastUtil.ToastShort("请输入手机号");

        }
    }
}
